<?php

namespace App\Jobs\Train\TrainOrder\Refund;

use App\Models\Train\TrainOrders\TrainOrder;
use App\Models\Trip\TripOrderRefund\TripOrderRefund;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Throwable;

class ProcessAfterTicketedRefundCheck implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private TrainOrder $order;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(TrainOrder $order)
    {
        $this->order = $order;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws Exception
     * @throws Throwable
     */
    public function handle()
    {
        $refund = new TripOrderRefund();
        $refund->applyTicketPriceDiffsRefund($this->order);
        $refund->applyUnMatchSelectSeatsRefund($this->order);
        $refund->applyChangedOriginOrderNeedRefund($this->order);
    }

    /**
     * 计算重试任务之前要等待的秒数。
     *
     * @return array
     */
    public function backoff()
    {
        return [120, 300];
    }
}
